package com.cyq.dascma.handler.valida.impl;

import com.cyq.dascma.constant.ValidaEnum;
import com.cyq.dascma.entity.Clazz;
import com.cyq.dascma.exception.ServiceException;
import com.cyq.dascma.handler.valida.Valida;
import com.cyq.dascma.result.ResultGenerator;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
 *
 * dingwen
 * 2021/4/4 15:47
 **/
public class ClazzValidaImpl implements Valida<Clazz> {
    @Override
    public void valida(ValidaEnum validaEnum, Clazz clazz) {
        if (ObjectUtils.isEmpty(clazz)) {
            throw new ServiceException(ResultGenerator.genFailureResult("clazz不能为空").setCode(400));
        }
        switch (validaEnum) {
            case ADD:
                if (!StringUtils.hasText(clazz.getClazzId())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("班级编号不能为空").setCode(400));
                }
                if (!StringUtils.hasText(clazz.getClazzName())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("班级名称不能为空").setCode(400));
                }
                if (!StringUtils.hasText(clazz.getClazzYear())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("班级年限不能为空").setCode(400));
                }
                break;
            case MODIFY:
                if (!StringUtils.hasText(clazz.getClazzId())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("班级编号不能为空").setCode(400));
                }
        }
    }
}
